package com.tz.dream.architect.mvp.list.demo;

import android.content.Context;

import com.tz.dream.architect.mvp.framework.lce.MvpLceView;
import com.tz.dream.architect.mvp.list.base.BasePresenter;
import com.tz.dream.architect.mvp.list.demo.bean.PostModel;
import com.tz.dream.architect.mvp.utils.HttpUtils;

/**
 * 作者: Dream on 16/9/24 21:28
 * QQ:510278658
 * E-mail:510278658@qq.com
 */
public class MyListPresenter extends BasePresenter<MvpLceView<PostModel>> {

    private MyListModel essenceModel;

    public MyListPresenter(Context context){
        super(context);
        this.essenceModel = new MyListModel(context);
    }

    public void getEssenceList(int type,boolean pullToRefresh){
        //1、显示Loading页面
        //显示LoadingView
        getView().showLoading(pullToRefresh);
        //2、发起请求的时候
        essenceModel.getEssenceList(0, type, new HttpUtils.OnLceHttpResultListener() {
            //3、更新UI->有两种情况
            @Override
            public void onCompleted() {
            }

            @Override
            public void onError(Throwable e) {
                //第一种情况：发送错误->请求失败
                //显示ErrorView
                getView().showError(e,false);
            }

            @Override
            public void onResult(Object result) {
                //第二种情况：正确->请求成功
                if (result == null){
                    //4、绑定数据->更新UI
                    getView().bindData((PostModel) result);
                }else {
                    getView().bindData((PostModel) result);
                }
                //5、显示UI->显示ContentView
                getView().showContent();
            }
        });
    }

}
